<template>
    <div class="defaultConfig">
        <channel-config ref="channelConfig"></channel-config>
        <div class="buttomBtn">
            <el-button size="small" type="primary" @click="submit">保存</el-button>
        </div>
    </div>
</template>

<script>
import channelConfig from "@/components/channelConfig";
import { editDefault } from "@/api/channel";
import { mapGetters } from "vuex";
export default {
    name: "defaultConfig",
    data() {
        return {
            defaultConfigId: "",
        }
    },
    methods: {
        setDefault(data) {
            if (Object.keys(data).length > 0) {
                this.defaultConfigId = data.id;
                this.$refs.channelConfig.setFromData(data);
            }
        },
        submit() {
            var param = this.$refs.channelConfig.getFromData();
            if (param) {
                param.id = this.defaultConfigId;
                editDefault(param).then(resp => {
                    if (resp.status == 0) {
                        this.$antMessage.success("修改成功");
                        this.$eventBus.$emit('updateDefaultSource');
                    } else {
                        this.$antMessage.warning(resp.message);
                    }
                });
            }
        }
    },
    mounted() {
        this.setDefault(this.defaultSourceConfig);
    },
    computed: {
        ...mapGetters(["defaultSourceConfig"]),
    },
    watch: {
        defaultSourceConfig(val) {
            this.setDefault(val);
        }
    },
    components: {
        channelConfig
    }
}
</script>

<style lang="scss">
.defaultConfig {
    position: relative;
    height: 100%;
    .channelConfig {
        height: calc(100% - 50px);
    }
    .buttomBtn {
        position: absolute;
        bottom: 0;
        right: 0;
    }
}
</style>